package com.example.springbootexception.controller;

import com.example.springbootexception.exception.GlobalException;
import com.example.springbootexception.result.CodeMsg;
import com.example.springbootexception.result.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @GetMapping("/index")
    public Result index(String name) {
        if(StringUtils.isEmpty(name)){
            //抛出自定义异常 CodeMsg为自定义的异常码
            throw new GlobalException(CodeMsg.BIND_ERROR.fillArgs(name));
        }
        return Result.success(name);
    }

}
